;!function () {
    var $ = layui.jquery;
    var e = layui.element();
    // 保存已经打开的tab
    // var tabIds = []; // $.inArray(id, tabIds) <= -1
    // 使用 JSON保存已经打开的 tab，相较数组操作性更强
    var tabIds = {};

    /**
     * 左侧导航单击事件
     */
    e.on('nav(left-nav)', function (el) {
            var id = el.children('a').attr('data-id');
            var t = el.text();
            if (!tabIds[id]) {
                e.tabAdd('layui-tab', {
                    title: t,
                    content: '<iframe src="table.html" style="width: 100%;border:0;"></iframe>',
                    id: id
                });
                $(window).trigger('resize');
                tabIds[id] = id;
            }
            e.tabChange('layui-tab', id);
        }
    );


    /**
     * 隐藏/显示左侧导航
     */
    $('.layui-side-toggle').on('click', function () {
        var sideWidth = $('#main-side').width();
        if (sideWidth === 200) {
            $('#main-body').animate({
                left: '0'
            });
            $('#main-footer').animate({
                left: '0'
            });
            $('#main-side').animate({
                width: '0'
            });
        } else {
            $('#main-body').animate({
                left: '200px'
            });
            $('#main-footer').animate({
                left: '200px'
            });
            $('#main-side').animate({
                width: '200px'
            });
        }
    });

    /**
     * 全屏显示
     */
    $('.layui-side-full').on('click', function () {
        var docElm = document.documentElement;
        //W3C
        if (docElm.requestFullscreen) {
            docElm.requestFullscreen();
        }
        //FireFox
        else if (docElm.mozRequestFullScreen) {
            docElm.mozRequestFullScreen();
        }
        //Chrome等
        else if (docElm.webkitRequestFullScreen) {
            docElm.webkitRequestFullScreen();
        }
        //IE11
        else if (elem.msRequestFullscreen) {
            elem.msRequestFullscreen();
        }
        layer.msg('按Esc即可退出全屏');
    });

    /**
     * resize 事件
     */
    $(window).on('resize', function () {
        var $content = $('.layui-tab-self .layui-tab-content');
        $content.height($(this).height() - 150);
        $content.find('iframe').each(function () {
            $(this).height($content.height());
        });
    }).resize();

    // 删除 tab关闭操作
    // $('li.tab-default').find('i.layui-tab-close').remove();

}();